<?php

namespace App\Http\Middleware;

use Closure;
use Exception;
use Illuminate\Http\Request;
use mszl\api\utils\ApiUtils;
use Symfony\Component\HttpFoundation\Response;

class VerifyMiniToken
{
    /**
     * 处理传入请求。
     *
     * @param Closure(Request): (Response) $next
     * @throws Exception
     */
    public function handle(Request $request, Closure $next):\Illuminate\Http\Response
    {
        if (empty(ApiUtils::getUserinfo())) throw new Exception('登录后操作', ApiUtils::API_CODE_LOGIN_ERROR);

        return $next($request);
    }

    /**
     * 在响应发送到浏览器后处理任务。
     */
    public function terminate(Request $request, Response $response): void
    {

    }
}
